// HSS.Forms.ExplorerNode.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       ExplorerNode.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
namespace HSS.Forms
{
	#region Using Directives
	using System;
	using System.Windows.Forms;
	using HSS.Data;
	#endregion

	/// <summary>
	/// An ExplorerNode extends a TreeNode and provides additional Callbacks for Managing the data the node represents.
	/// </summary>
	public class ExplorerNode : TreeNode, IUIDataElement
	{
		#region Constructor
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="Text">The Text for this Node</param>
		public ExplorerNode(string Text)
			: base(Text)
		{
		}
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="Text">The Text for this Node</param>
		/// <param name="ImageIndex">The index of the image from the ImageList</param>
		/// <param name="DataTypeName">The Assembly Qualified Name</param>
		public ExplorerNode(string Text, int ImageIndex, string DataTypeName)
			: base(Text, ImageIndex, ImageIndex)
		{
			this._dataTypeName = DataTypeName;
		}
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="Text">The Text for this Node</param>
		/// <param name="ImageKey">The name of the image from the ImageList</param>
		/// <param name="DataTypeName">The Assembly Qualified Name</param>
		public ExplorerNode(string Text, string ImageKey, string DataTypeName)
			: base(Text)
		{
			this.ImageKey = ImageKey;
			this.SelectedImageKey = ImageKey;
			this._dataTypeName = DataTypeName;
		}
		/// <summary>
		/// Constructs a new Node, using the Data.Name as the Nodes Text
		/// </summary>
		/// <param name="Data">The data this Node represents</param>
		public ExplorerNode(IDataContainer Data)
			: base(Data.Name)
		{
			this.Data = Data;
		}
		/// <summary>
		/// Constructs a new Node, using the Data.Name as the Nodes Text
		/// </summary>
		/// <param name="Data">The data this Node represents</param>
		/// <param name="ImageIndex">The index of the image from the ImageList</param>
		public ExplorerNode(IDataContainer Data, int ImageIndex)
			: base(Data.Name, ImageIndex, ImageIndex)
		{
			this.Data = Data;
		}
		/// <summary>
		/// Constructs a new Node, using the Data.Name as the Nodes Text
		/// </summary>
		/// <param name="Data">The data this Node represents</param>
		/// <param name="ImageKey">The name of the image from the ImageList</param>
		public ExplorerNode(IDataContainer Data, string ImageKey)
			: base(Data.Name)
		{
			this.ImageKey = ImageKey;
			this.SelectedImageKey = ImageKey;
			this.Data = Data;
		}
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the Data that is the source for this node
		/// </summary>
		public IDataContainer Data
		{
			get { return _data; }
			set
			{
				_data = value;
				if (null == _data)
					_dataTypeName = string.Empty;
				else
					_dataTypeName = _data.GetType().AssemblyQualifiedName;
			}
		} IDataContainer _data;
		/// <summary>
		/// Gets the type name of the type of Data
		/// </summary>
		public string DataTypeName
		{
			get
			{
				if (string.IsNullOrEmpty(_dataTypeName))
				{
					if (null == _data)
						_dataTypeName = string.Empty;
					else
						_dataTypeName = _data.GetType().Name;
				}
				return _dataTypeName;
			}
		} string _dataTypeName;
		/// <summary>
		/// Gets the Type of Data
		/// </summary>
		public Type DataType
		{
			get
			{
				if (null == _data)
					return null;
				return _data.GetType();
			}
		}
		#endregion
	}
}